package com.uchengwang.ui.utils;

import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.uchengwang.R;

import pl.droidsonroids.gif.GifImageView;

/**
 * Created by U城网 on 2017/6/24.
 */

public class LoadingUtils {
    private AlertDialog dialog;
    private static LoadingUtils utils;
    private LoadingUtils(){}

    private GifImageView loading_image;

    public static LoadingUtils getUtils() {
        if (utils == null){
            utils = new LoadingUtils();
        }
        return utils;
    }

    /**
     * 显示 加载
     * */
    public AlertDialog loading(Context context) {//登录注册界面的dialog
        if (dialog != null && dialog.isShowing()){
            return dialog;
        }

        dialog = new AlertDialog.Builder(context, R.style.dialog).create();
        View view = View.inflate(context, R.layout.layout_loading, null);
        loading_image = (GifImageView) view.findViewById(R.id.loading_image);

        dialog.setCanceledOnTouchOutside(false);
        view.setLayoutParams(new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        dialog.setView(view, 0, 0, 0, 0);
        dialog.show();
        return dialog;
    }

    /**
     * 隐藏
     * */
    public void hide(){
        if (dialog != null && dialog.isShowing()){
            dialog.cancel();
            utils = null;
        }

    }
}
